package com.wzcl.app.model.vo;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.wzcl.app.dao.model.SysDict;
import com.wzcl.app.dao.model.SysDictInfo;
import com.wzcl.app.service.SysDictService;
import com.wzcl.app.utils.SpringUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(value={"translationMap"})
public abstract class BaseVo implements Serializable {
    private static final long serialVersionUID = 1L;
    public static final String DEFAULT_IMAGE = "DEFAULT_IMAGE";
    public static final String DEFAULT_AVATAR_IMAGE = "DEFAULT_AVATAR_IMAGE";


    private Map<String, Map<Integer,String>> translationMap = null;

    //--------------公共属性------------//
    private Integer id;

    private Date createTime;

    private Date updateTime;

    //-----------------------------//

    public abstract void translationValueStr();

    public abstract void processResources();

    public final Map<String,Map<Integer,String>> getTranslationMap(){
        if(translationMap == null){
            initTranslationMap();
        }
        return translationMap;
    }


    private void initTranslationMap(){
        SysDictService systemDictionaryService = (SysDictService) SpringUtil.getBean("sysDictServiceImpl");
        List<SysDict> systemDictionaryList = systemDictionaryService.getSysDictList();
        Map<String, Map<Integer, String>> stringMapHashMap = new HashMap<>();
        for (SysDict systemDictionary : systemDictionaryList) {
            HashMap<Integer, String> infoMap = new HashMap<>();
            for (SysDictInfo info : systemDictionary.getInfoList()) {
                infoMap.put(info.getValueName(),info.getDepict());
            }
            stringMapHashMap.put(systemDictionary.getKeyName(),infoMap);
        }
        translationMap = stringMapHashMap;
    }

}
